﻿using System; 
using System.Data; 
using System.Collections.Generic; 

namespace Dala.Samples.DataAccessLayer
{
  
  public class Product 
  {
    public Int32 ProductId{get;set;}
    public String ProductName{get;set;}
    public String ItemNumber{get;set;}
    public String CategoryName{get;set;}
    public Decimal Price{get;set;}
    
    public const int ProductIdMinValue = 0;
    
    public static List<Product> GenerateProductCollectionFromReader(IDataReader returnData)
    {
    	
        List<Product> colProduct = new List<Product>();
        while (returnData.Read())
        {
            Product newProduct = new Product();       
    				newProduct.ProductId = returnData["ProductId"] == System.DBNull.Value ? 0 : (Int32)returnData["ProductId"];
    				newProduct.ProductName = returnData["ProductName"] == System.DBNull.Value ? null : (String)returnData["ProductName"];
    				newProduct.ItemNumber = returnData["ItemNumber"] == System.DBNull.Value ? null : (String)returnData["ItemNumber"];
    				newProduct.CategoryName = returnData["CategoryName"] == System.DBNull.Value ? null : (String)returnData["CategoryName"];
    				newProduct.Price = returnData["Price"] == System.DBNull.Value ? 0 : (Decimal)returnData["Price"];
    				
    		//adding the Product to the collection
    		colProduct.Add(newProduct);
        }
    
        //returns the collection of Product objects
        return (colProduct);
    }//GenerateCollectionFromReader ends
  }//end Product class
  
  public class Location 
  {
    public Int32 LocationId{get;set;}
    public String Name{get;set;}
    public String Address{get;set;}
    public String City{get;set;}
    public String State{get;set;}
    public String ZipCode{get;set;}
    public String Latitude{get;set;}
    public String Longitude{get;set;}
    
    public const int LocationIdMinValue = 0;
    
    public static List<Location> GenerateLocationCollectionFromReader(IDataReader returnData)
    {
    	
        List<Location> colLocation = new List<Location>();
        while (returnData.Read())
        {
            Location newLocation = new Location();       
    				newLocation.LocationId = returnData["LocationId"] == System.DBNull.Value ? 0 : (Int32)returnData["LocationId"];
    				newLocation.Name = returnData["Name"] == System.DBNull.Value ? null : (String)returnData["Name"];
    				newLocation.Address = returnData["Address"] == System.DBNull.Value ? null : (String)returnData["Address"];
    				newLocation.City = returnData["City"] == System.DBNull.Value ? null : (String)returnData["City"];
    				newLocation.State = returnData["State"] == System.DBNull.Value ? null : (String)returnData["State"];
    				newLocation.ZipCode = returnData["ZipCode"] == System.DBNull.Value ? null : (String)returnData["ZipCode"];
    				newLocation.Latitude = returnData["Latitude"] == System.DBNull.Value ? null : (String)returnData["Latitude"];
    				newLocation.Longitude = returnData["Longitude"] == System.DBNull.Value ? null : (String)returnData["Longitude"];
    				
    		//adding the Location to the collection
    		colLocation.Add(newLocation);
        }
    
        //returns the collection of Location objects
        return (colLocation);
    }//GenerateCollectionFromReader ends
  }//end Location class
}//end namespace

